library TextSystem requires GlobalVariables

	//=======================================================================
	// Multiboard
	//===========================================================================

	function mSortedSwap takes integer A, integer B returns nothing
		local integer i = udg_Sorted[A]
		set udg_Sorted[A] = udg_Sorted[B]
		set udg_Sorted[B] = i
	endfunction

	function PlayerDied takes integer A returns nothing
		local integer B = 1
		set udg_Hero[A] = null
		set udg_PlayerDead[A] = true
		if udg_MBcolors[A]!=3 then
			set udg_MBcolors[A] = 0
		endif
		loop
			exitwhen udg_Sorted[B] == A
			set B = B + 1
		endloop
		call mSortedSwap(B,udg_Players)
		set udg_Players = udg_Players - 1
		if udg_Players<=4 then
			set udg_Spawn = udg_Players
		endif
	endfunction



	/// =======================================================
	/// fading text
	/// =======================================================

	function AddFadingTextTag takes string text, real x, real y, integer red, integer green, integer blue, integer alpha returns nothing
		local texttag t = CreateTextTag()
		call SetTextTagText(t, text, 0.025)
		call SetTextTagPos(t, x, y, 0.0)
		call SetTextTagColor(t,red,green,blue,alpha)
		call SetTextTagVelocity(t, 0, 0.03)
		call SetTextTagVisibility(t, true)
		call SetTextTagFadepoint(t, 2)
		call SetTextTagLifespan(t, 3)
		call SetTextTagPermanent(t, false)
		set t = null
	endfunction

	function GeneralText takes real duration, string message returns nothing
		call StartSound(gg_snd_Radio)
		call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,duration,message)
	endfunction

	function ALICEText takes real duration, string message returns nothing
		call StartSound(gg_snd_ALICEBeep)
		call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,duration,message)
	endfunction

	function ALICE2Text takes real duration, string message returns nothing
		call StartSound(gg_snd_ALICEBeep2)
		call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0,duration,message)
	endfunction

	function FieldChat takes unit u, real time, string text returns nothing
		local texttag t
		local real x
		local real y
		if GetWidgetLife(u)>0.405 then
		set x = GetUnitX(u)
		set y = GetUnitY(u)
		call StartSound(gg_snd_Radio)
		set t = CreateTextTag()
		call SetTextTagText(t, text, 0.02)
		call SetTextTagPos(t, x, y, 35.0)
		call SetTextTagVisibility(t, true)
		call SetTextTagLifespan(t, time)
		call SetTextTagPermanent(t, false)
		endif
		set t = null
	endfunction

	function SimpleChat takes unit u, real time, string text returns nothing
		local texttag t
		local real x
		local real y
		if GetWidgetLife(u)>0.405 then
		set x = GetUnitX(u)
		set y = GetUnitY(u)
		set t = CreateTextTag()
		call SetTextTagText(t, text, 0.02)
		call SetTextTagPos(t, x, y,60.0)
		call SetTextTagVisibility(t, true)
		call SetTextTagLifespan(t, time)
		call SetTextTagPermanent(t, false)
		endif
		set t = null
	endfunction

	function RadioChat takes unit u, real time, string text returns nothing
		if GetWidgetLife(u)>0.405 then
			call StartSound(gg_snd_Radio)
			call DisplayTimedTextToPlayer(GetLocalPlayer(),0.0,0.0,time,text)
		endif
	endfunction

	function print takes string s returns nothing
		call DisplayTextToForce( GetPlayersAll(), " " + s )
	endfunction

endlibrary